package com.loong.web.gp4j.view.manage;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.loong.web.gp4j.bean.schema.user.Auths;
import com.loong.web.gp4j.service.statistic.StatisticService;
import com.loong.web.suppert.collection.vo.ResultVo;
import com.loong.web.suppert.collection.vo.ResultVoFactory;
import com.loong.web.suppert.intercept.auth.AuthType;

/**
 * 统计资源
 *
 * @author 张成轩
 */
@Controller
@RequestMapping("manage/statistics")
public class StatisticsViewMapping {

	@Resource
	private StatisticService statisticService;

	/**
	 * 统计页面
	 * 
	 * @param request 请求
	 * @return 视图
	 */
	@RequestMapping(value = "", method = RequestMethod.GET)
	@AuthType(Auths.SYS_MANAGER)
	public ModelAndView statistics(HttpServletRequest request) {

		return new ModelAndView("gp4j/manage/statistics");
	}

	/**
	 * 获取访问路径统计
	 * 
	 * @param days 查询天数
	 * @return 返回对象
	 */
	@RequestMapping(value = "name", method = RequestMethod.POST)
	@ResponseBody
	@AuthType(Auths.SYS_MANAGER)
	public ResultVo<?> name(Integer days) {

		if (days == null)
			return ResultVoFactory.fail("查询天使不能为空");
		return statisticService.names(days);
	}

	/**
	 * 获取操作系统统计
	 * 
	 * @param days 查询天数
	 * @return 返回对象
	 */
	@RequestMapping(value = "env", method = RequestMethod.POST)
	@ResponseBody
	@AuthType(Auths.SYS_MANAGER)
	public ResultVo<?> env(Integer days) {

		if (days == null)
			return ResultVoFactory.fail("查询天使不能为空");
		return statisticService.envs(days);
	}
}
